-- die_drop_item
-- created by shuzy
-- 死亡掉落许多堆物品

return {
    apply = function(prop, baseValue)
        return baseValue + prop[3];
    end,

    -- 死亡触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_MONSTER then
            return;
        end

        local dropNum  = tonumber(prop[3]);

        -- 设置奖励
        local element = tonumber(prop[2]);
        local class = DungeonM.queryElement(element, "class");
        local centerPos = who:getPos();

        -- 多次掉落
        for i = 1, dropNum do
            -- 找个空位（包含障碍格）
            pos = SummonM.findSummonPos(centerPos, false, true);

            if pos <= 0 then
                -- 没有空格了就不掉了
                return;
            end

            local dbase = DungeonM.queryElement(element, "dbase");
            if type(dbase["drop_stat"]) == "table" then
                if BuildingBonusM.getFieldStat(dbase["drop_stat"][1]) >= dbase["drop_stat"][2] then
                    -- 已经不能再掉了
                    return;
                end

                -- 统计掉落
                BuildingBonusM.addFieldStat(dbase["drop_stat"][1]);
            end

            local para = { ["class"] = class, ["element"] = element };
            DungeonM.transformGrid(class, pos, GRID_STATE_OPEN, para);
        end

        return true;
    end,

    record = function(target, prop, path)
        return false;
    end
};
